import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

/**
 * tester class for the debit card class.
 * @author Kyle Scharnhorst/Kristopher Gooding
 * @version 04/25/2014
 */
public class DebitCardTest {
	/**
	 * Debit card limit.
	 */
	private static int LIMIT = 100;

	/**
	 * Delta, the difference accepted when doing an equals assertion on
	 * numerical values.
	 */
	private static int DELTA = 0;

	/**
	 * checkingAccount debit amount.
	 */
	private static float DEBIT_AMOUNT = 100;

	/**
	 * First pay amount.
	 */
	private static double A_PAY_AMOUNT = 110;

	/**
	 * Second pay amount.
	 */
	private static double ANOTHER_PAY_AMOUNT = 10;

	/**
	 * Debit card instantiated with the basic constructor.
	 */
	private DebitCard my_first_constructor;

	/**
	 * Debit card instantiated with the overloaded constructor.
	 */
	private DebitCard my_overloaded_debit;

	/**
	 * Checking account linked to debit card.
	 */
	private CheckingAccount my_checking_account;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		// my_checking_account = new CheckingAccount(0);
		my_checking_account = new CheckingAccount("", "", "", "", "",
				DEBIT_AMOUNT);
		my_first_constructor = new DebitCard("jim", "street", "town", "90210",
				"'merica");
		my_overloaded_debit = new DebitCard("jim", "street", "town", "90210",
				"'merica", LIMIT, my_checking_account);
	}

	/**
	 * Test method for
	 * {@link DebitCard#DebitCard(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}
	 * .
	 */
	@Test
	public void testDebitCardStringStringStringStringString() {
		assertTrue(my_first_constructor.getMember().getName().equals("jim"));
		assertTrue(my_first_constructor.getMember().getAddress()
				.getStreet().equals("street"));
		assertTrue(my_first_constructor.getMember().getAddress().getTown()
				.equals("town"));
		assertTrue(my_first_constructor.getMember().getAddress()
				.getZipCode().equals("90210"));
		assertTrue(my_first_constructor.getMember().getAddress()
				.getCountry().equals("'merica"));
	}

	/**
	 * Test method for
	 * {@link DebitCard#DebitCard(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, double, CheckingAccount)}
	 * .
	 */
	@Test
	public void testDebitCardStringStringStringStringStringDoubleCheckingAccount() {
		assertTrue(my_overloaded_debit.getMember().getName().equals("jim"));
		assertTrue(my_overloaded_debit.getMember().getAddress()
				.getStreet().equals("street"));
		assertTrue(my_overloaded_debit.getMember().getAddress().getTown()
				.equals("town"));
		assertTrue(my_overloaded_debit.getMember().getAddress()
				.getZipCode().equals("90210"));
		assertTrue(my_overloaded_debit.getMember().getAddress()
				.getCountry().equals("'merica"));
		// limit is never used
		assertEquals(my_overloaded_debit.getAccountConnectedTo(),
				my_checking_account);
	}

	/**
	 * Test method for {@link DebitCard#pay(double)}.
	 */
	@Test
	public void testPay() {
		// initial balance is 0 by default.
		CheckingAccount connected_account = my_overloaded_debit
				.getAccountConnectedTo();

		my_overloaded_debit.pay(ANOTHER_PAY_AMOUNT); // designed not to satisfy
														// if condition
		assertEquals(connected_account.getBalance(), 0, DELTA);

		my_overloaded_debit.pay(A_PAY_AMOUNT);// designed to satisfy if
												// condition
		assertEquals(connected_account.getBalance(), -A_PAY_AMOUNT, DELTA);

	}

}
